﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.TxValueStepStepSizeDlg
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using DnProcessSimulateCommands.MultipleLocationsManipulation.ValueStepControl.Resources;
using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using Tecnomatix.Engineering;
using Tecnomatix.Engineering.Ui;


namespace DnProcessSimulateCommands;

public class TxValueStepStepSizeDlg : TxForm
{
  private TxValueStepType _stepType;
  private double _stepValue;
  private static double MAX_ROTATION_STEP = Math.PI;
  private static double MIN_ROTATION_STEP = 0.00017453292519943296;
  private static double MAX_TRANSLATION_STEP = 100000.0;
  private static double MIN_TRANSLATION_STEP = 0.01;
  private IContainer components;
  private Button btnCancel;
  private Button btnOK;
  private Label lblStepTitle;
  private TxNumericEditBoxCtrl txnebStepSize;

  public double StepValue
  {
    get
    {
      switch (this._stepType)
      {
        case TxValueStepType.Linear:
          return this._stepValue / TxApplication.Options.Units.LinearMultiplier;
        case TxValueStepType.Angular:
          return this._stepValue / TxApplication.Options.Units.AngularMultiplier;
        default:
          return 0.0;
      }
    }
    set
    {
      switch (this._stepType)
      {
        case TxValueStepType.Linear:
          this._stepValue = value * TxApplication.Options.Units.LinearMultiplier;
          break;
        case TxValueStepType.Angular:
          this._stepValue = value * TxApplication.Options.Units.AngularMultiplier;
          break;
      }
    }
  }

  public TxValueStepStepSizeDlg(TxValueStepType stepType, double stepValue)
  {
    this.InitializeComponent();
    this._stepType = stepType;
    this.StepValue = stepValue;
    this.InitFormContent();
  }

  private void InitFormContent()
  {
    double num1 = 0.0;
    double num2 = 0.0;
    switch (this._stepType)
    {
      case TxValueStepType.Linear:
        this.lblStepTitle.Text = string.Format(TxValueStepResource.TranslationStepCaption, (object) TxApplication.Options.Units.LinearUnitName);
        num1 = TxValueStepStepSizeDlg.MIN_TRANSLATION_STEP;
        num2 = TxValueStepStepSizeDlg.MAX_TRANSLATION_STEP;
        this.txnebStepSize.ValueType = (TxNumericEditValueType) 0;
        break;
      case TxValueStepType.Angular:
        this.lblStepTitle.Text = string.Format(TxValueStepResource.RotationStepCaption, (object) TxApplication.Options.Units.AngularUnitName);
        num1 = TxValueStepStepSizeDlg.MIN_ROTATION_STEP;
        num2 = TxValueStepStepSizeDlg.MAX_ROTATION_STEP;
        this.txnebStepSize.ValueType = (TxNumericEditValueType) 1;
        break;
    }
    this.txnebStepSize.LowerBound = num1;
    this.txnebStepSize.UpperBound = num2;
    this.txnebStepSize.Value = this._stepValue;
  }

  private void TxValueStepStepSizeDlg_Load(object sender, EventArgs e)
  {
    ((Control) this.txnebStepSize).Select();
    this.txnebStepSize.Focus();
  }

  private void btnCancel_Click(object sender, EventArgs e)
  {
    ((Form) this).DialogResult = DialogResult.Cancel;
    ((Form) this).Close();
  }

  private void btnOK_Click(object sender, EventArgs e)
  {
    this.txnebStepSize.Focus();
    this._stepValue = this.txnebStepSize.Value;
    ((Form) this).DialogResult = DialogResult.OK;
    ((Form) this).Close();
  }

  private void txnebStepSize_TentativeValueChanged(
    object sender,
    TxNumericEditBoxCtrl_TentativeValueChangedEventArgs args)
  {
    if (this.txnebStepSize.IsValid())
      this.btnOK.Enabled = true;
    else
      this.btnOK.Enabled = false;
  }

  protected virtual void Dispose(bool disposing)
  {
    if (disposing && this.components != null)
      this.components.Dispose();
    base.Dispose(disposing);
  }

  private void InitializeComponent()
  {
    ComponentResourceManager componentResourceManager = new ComponentResourceManager(typeof (TxValueStepStepSizeDlg));
    this.btnCancel = new Button();
    this.btnOK = new Button();
    this.lblStepTitle = new Label();
    this.txnebStepSize = new TxNumericEditBoxCtrl();
    ((Control) this).SuspendLayout();
    this.btnCancel.DialogResult = DialogResult.Cancel;
    componentResourceManager.ApplyResources((object) this.btnCancel, "btnCancel");
    this.btnCancel.Name = "btnCancel";
    this.btnCancel.UseVisualStyleBackColor = true;
    this.btnCancel.Click += new EventHandler(this.btnCancel_Click);
    componentResourceManager.ApplyResources((object) this.btnOK, "btnOK");
    this.btnOK.Name = "btnOK";
    this.btnOK.UseVisualStyleBackColor = true;
    this.btnOK.Click += new EventHandler(this.btnOK_Click);
    componentResourceManager.ApplyResources((object) this.lblStepTitle, "lblStepTitle");
    this.lblStepTitle.MaximumSize = new Size(139, 0);
    this.lblStepTitle.Name = "lblStepTitle";
    this.txnebStepSize.BorderStyle = BorderStyle.Fixed3D;
    componentResourceManager.ApplyResources((object) this.txnebStepSize, "txnebStepSize");
    this.txnebStepSize.LowerBound = -1000000.0;
    ((Control) this.txnebStepSize).Name = "txnebStepSize";
    this.txnebStepSize.ReadOnly = false;
    this.txnebStepSize.StepSize = 1.0;
    this.txnebStepSize.TextAlign = HorizontalAlignment.Left;
    this.txnebStepSize.ThousandsSeparator = false;
    this.txnebStepSize.UpperBound = 1000000.0;
    this.txnebStepSize.Value = 0.0;
    this.txnebStepSize.ValueType = (TxNumericEditValueType) 0;
    this.txnebStepSize.TentativeValueChanged += new TxNumericEditBoxCtrl_TentativeValueChangedEventHandler(this.txnebStepSize_TentativeValueChanged);
    ((Form) this).AcceptButton = (IButtonControl) this.btnOK;
    componentResourceManager.ApplyResources((object) this, "$this");
    ((ContainerControl) this).AutoScaleMode = AutoScaleMode.Font;
    ((Form) this).CancelButton = (IButtonControl) this.btnCancel;
    ((Control) this).Controls.Add((Control) this.txnebStepSize);
    ((Control) this).Controls.Add((Control) this.btnCancel);
    ((Control) this).Controls.Add((Control) this.btnOK);
    ((Control) this).Controls.Add((Control) this.lblStepTitle);
    ((Form) this).FormBorderStyle = FormBorderStyle.FixedDialog;
    ((Form) this).MaximizeBox = false;
    ((Form) this).MinimizeBox = false;
    ((Control) this).Name = nameof (TxValueStepStepSizeDlg);
    ((Form) this).Load += new EventHandler(this.TxValueStepStepSizeDlg_Load);
    ((Control) this).ResumeLayout(false);
    ((Control) this).PerformLayout();
  }
}
